//
//  UserInfo.m
//  ZhuanQi
//
//  Created by Davy on 16/5/17.
//  Copyright © 2016年 Davy. All rights reserved.
//

#import "User.h"

@implementation User



// 存放唯一的一个实例
static  User *_instance;
// 重写allocWithZone（alloc最终还是要调用allocWithZone）
+ (id)allocWithZone:(NSZone *)zone
{
    static dispatch_once_t onceToken;
    /*
     1.不用管多线程问题
     2.能保证block里面的代码永远只调用一次
     */
    // 保证多次调用allocWithZone后都返回同一个对象
    dispatch_once(&onceToken, ^{
        _instance = [super allocWithZone:zone];
    });
    
    return _instance;
}


+ (User *)sharedUser
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init];
        
    });
    return _instance;
}

+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{
             @"userId":@"id",
             @"avatar":@"img",
             @"phone":@"usr",
             @"nickname":@"nme",
             @"userId":@"id",
             @"avatar":@"img",
             @"type":@"tye",
             @"wxOpenID": @"wx_id",
             @"qqOpenID": @"qq_id",
             };
}
//@property (nonatomic, copy) NSString *userId;
//@property (nonatomic, copy) NSString *phone;
//@property (nonatomic, copy) NSString *openId;
//@property (nonatomic, copy) NSString *avatar;
//@property (nonatomic, copy) NSString *nickname;
//id": "5",
//"usr": "18100616738",
//"tye": "1",
//"nme": "yanjin",
//"img": "http://www.yanjin.pro/web0/zzb/adm/images/mz.jpg",
//"province": "江苏省",
//"city": "南京市",
//"area": "雨花台区",
//"dte": "2020-08-31 12:23:54",
//"token": "55c3b01428444f162288c891fdcb044f",
//"ste": "1"

+(BOOL)isLogined{
    if ([User sharedUser].userId && [User sharedUser].userId.length > 0 ) {
        return YES;
    }else{
        return NO;
    }
}

+(BOOL)isGuest{
    if (![User sharedUser].userId || [User sharedUser].userId.length == 0 ) {
        return YES;
    }else{
        return NO;
    }
}

WZLSERIALIZE_CODER_DECODER();
WZLSERIALIZE_COPY_WITH_ZONE();

@end
